package com.burgeon.backend.SHOP.rest;
/**
 * 根据id查找退款单
 */

import com.burgeon.backend.Rest.base.RESTBase;
import org.json.JSONArray;
import org.springframework.util.MultiValueMap;

import java.util.ArrayList;
import java.util.HashMap;

public class GetRefundById extends RESTBase {

    private String ip;
    private String account;
    private String password;

    public GetRefundById(String ip, String account, String password) {
        this.ip = ip;
        this.account = account;
        this.password = password;
    }

    /**
     * 发送并接收字符创
     */

    public HashMap getData(String id) throws Exception {
        String url = "http://" + ip + "/servlets/binserv/Rest";

        String str = RESULT(Data(id), url);

        String code = new JSONArray(str).getJSONObject(0).getString("code");
        if (!"0".equals(code)) {
            throw new Exception();
        }
        HashMap hashMap = new HashMap();
        JSONArray jsonArray = new JSONArray(str).getJSONObject(0).getJSONArray("rows");

        hashMap.put("id",jsonArray.getJSONArray(0).getString(0));
        hashMap.put("store",jsonArray.getJSONArray(0).getString(1));
        hashMap.put("address",jsonArray.getJSONArray(0).getString(2));
        hashMap.put("phone",jsonArray.getJSONArray(0).getString(3));
        hashMap.put("contactor",jsonArray.getJSONArray(0).getString(4));

        return hashMap;

    }

    private MultiValueMap Data(String id) {
        HashMap params = new HashMap();
        ArrayList columns = new ArrayList();//查询字段
        columns.add("ID");
        columns.add("'C_STORE_ID;NAME'");//店名
        columns.add("ADDRESS");//电话
        columns.add("PHONE");//地址
        columns.add("CONTACTOR");//收货人

        params.put("columns", columns);
        params.put("table", "YC_V2_RET_RETAIL");//表名

        params.put("count", "true");

        HashMap paramss = new HashMap();
        String ac = "'="+id+"'";
        paramss.put("column", "ID");
        paramss.put("condition", ac);
        params.put("params", paramss);
        params.put("count","true");

        return DATA("Query", params, account, password);
    }

    public static void main(String[] args) {
        GetRefundById g = new GetRefundById("59.110.28.94:90", "nea@burgeon.com.cn", "burgeon55321");
        try {
            System.err.println(g.getData("20"));
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
